<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>审核页面</title>
	<script th:src="@{/layui/layui.js}" type="text/javascript"></script>
	<link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
</head>
<body>
	<div class="layui-panel"style="padding: 8px;">
		    <fieldset class="layui-elem-field layui-border-green">
		        <legend>信息</legend>
		        <form class="layui-form layui-form-pane" style="margin: 20px;">
		            <div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">名称</label>
							<div class="layui-input-inline">
								<input class="layui-input" type="text" name="name"autocomplete="off" />
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline">
								<a class="layui-btn layui-btn-primary"lay-submit="" lay-filter="searchBtn">
									<li class="layui-icon layui-icon-search">搜索</li>
								</a>
							</div>
						</div>
					</div>
		        </form>
		    </fieldset>
		   </div>
			<table class="layui-hide" id="commentsTable" lay-filter="commentsTable"></table>
			<script id="tool"type="text/html" >
			<a class="layui-btn layui-btn-normal layui-btn-xs"lay-event="review">回复</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs"lay-event="delete">删除</a>
		</script>
<script>
	var $;
layui.use(['table','rate','jquery'], function(){
  var table = layui.table,
  rate=layui.rate;
  $=layui.jquery;
  table.render({
    elem: '#commentsTable',
    	page:true,
    	limit:10,
    	limits:[5,10,20,30],
    url:'/system/cc/find',
   	toolbar:'#tableBar',
    cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增,
    cols: [
    		[
      {type:'member',fixed:'left',width:45},
      {type:'checkbox',fixed:'left'},
	  {field:'id', width:100, title: '序列ID', sort: true},
      {field:'userId', width:100, title: '用户ID', sort: true},
      {field:'goodIds', width:180, title: '商品ID', sort: true},
      {field:'score', width:100,align:'center', title: '评分'},
      {field:'content', width:480,align: 'center',title: '评论内容'},
      {field:'photo', title: '评论图片'},
      {field:'createTime', title: '时间', sort: true},
      {fixed:'right',title:'操作',width:120,align:'center',toolbar:'#tool'}
    ]
	],
    done:function(res){
            var data = res.data;
            console.log(data)
            for (var item in data) {
                rate.render({
                    elem: '#score'+data[item].id+'',
                    length: 5,
                    value: data[item].score,
                    theme: '#f30808',
                    half: true,
                    text: false,
                    readonly: true
                });
            }
      }
  
  });
	var active={
		dialog:function (content){
			layer.open({
				type:2,
				content:content,
				area:['800px','750px'],
				maxmin:true,
				btn:['关闭'],
			})
		},
		deleted:function (id){
			$.ajax({
				type:'post',
				url: '/system/cc/delete?id='+id,
				dataType:'json',
				success:function (result) {
					layer.msg(result.msg);
					if(result.is){
						let index =parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);//关闭父页面窗口
					}
				}
			})
		}
	}

	table.on('tool(commentsTable)',function (obj) {
		var event = obj.event;
		if("review" == event){
			alert("empty!")
			//active.dialog('/page/system/listLook/'+obj.data.uid);
		}
		else if("delete"==event){
			layer.confirm("确认要删除ID为"+obj.data.id+"的评论吗",function (){
				active.deleted(obj.data.id);
			})
		}
		else if("edit"==event){
			alert("这是编辑功能")//TODO 商品上架的接口
		}
	})
  
});
</script>

</body>
</html>